'use strict';

module.exports = {
	async up(queryInterface, Sequelize) {
		/**
		 * Add altering commands here.
		 *
		 * Example:
		 * await queryInterface.createTable('users', { id: Sequelize.INTEGER });
		 */
		const { INTEGER, STRING, DATE, ENUM, TEXT } = Sequelize;

		return queryInterface.createTable('share', {
			id: {
				type: INTEGER(20),
				primaryKey: true,
				autoIncrement: true
			},
			sharedurl: {
				type: STRING,
				allowNull: true,
				default: '',
				comment: '分享链接'
			},
			file_id: {
				type: INTEGER,
				allowNull: false,
				defaultValue: 0,
				comment: '文件id',
				references: {
					model: 'file',
					key: 'id'
				},
				onDelete: 'cascade',
				onUpdate: 'restrict' // 更新时操作
			},
			iscancel: {
				type: INTEGER(1),
				allowNull: false,
				defaultValue: 0,
				comment: '是否取消分享'
			},
			user_id: {
				type: INTEGER,
				allowNull: false,
				defaultValue: 0,
				comment: '用户id',
				references: {
					model: 'user',
					key: 'id'
				},
				onDelete: 'cascade',
				onUpdate: 'restrict' // 更新时操作
			},
			created_time: DATE,
			updated_time: DATE
		});
	},

	async down(queryInterface, Sequelize) {
		/**
		 * Add reverting commands here.
		 *
		 * Example:
		 * await queryInterface.dropTable('users');
		 */
		return queryInterface.dropTable('share');
	}
};
